package com.gdust.gkyx.acl.controller;

import com.gdust.gkyx.acl.service.PermissionService;
import com.gdust.gkyx.common.result.Result;
import com.gdust.gkyx.model.acl.Permission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: PermissionAdminController
 * Package: com.gdust.gkyx.acl.controller
 * Description:权限管理模块-菜单管理
 * 开发菜单管理
 *
 * 参考前端：src >api >acl >permission.js进行接口开发
 * @Author syun
 * @Create 2025/1/24 9:55
 * @Version 1.0
 */
@RestController
@RequestMapping("/admin/acl/permission")
@Api(tags = "菜单管理")
//@CrossOrigin //跨域
public class PermissionAdminController {
    //注入权限表的service
    @Autowired
    private PermissionService permissionService;

    /**
     *     //查询所有菜单
     * //    url: `${api_name}`,
     * //    method: 'get'
     * @return
     */
    @ApiOperation("查询所有菜单")
    @GetMapping
    public Result list() {
        //自定义方法：查询所有菜单
        List<Permission> list = permissionService.queryAllPermission();
        return Result.ok(list);
    }


    /**
     *     //添加菜单
     * //    url: `${api_name}/save`,
     * //    method: "post",
     * //    data: permission
     * @param permission 权限对象
     * @return
     */
    @ApiOperation("添加菜单")
    @PostMapping("save")
    public Result save(@RequestBody Permission permission) {
        //自定义方法：添加菜单
        permissionService.save(permission);
        return Result.ok(null);
    }

    /**
     *     //修改菜单
     * //    url: `${api_name}/update`,
     * //    method: "put",
     * //    data: permission
     * @param permission 权限对象
     * @return
     */
    @ApiOperation("修改菜单")
    @PutMapping("update")
    public Result update(@RequestBody Permission permission) {
        //自定义方法：修改菜单
        permissionService.updateById(permission);
        return Result.ok(null);
    }

    /**
     *
     //递归删除菜单
     //    url: `${api_name}/remove/${id}`,
     //    method: "delete"
     * @param id 编号
     * @return
     */
    @ApiOperation("递归删除菜单")
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable Long id) {
        //自定义方法：递归删除菜单
        permissionService.removeChildById(id);
        return Result.ok(null);
    }


}
